package com.zsule.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.zsule.entity.PageEntity;
import com.zsule.entity.SmokeCert;
import com.zsule.frameworks.mongodb.service.MongoAbstractService;
import com.zsule.service.ISmokeCertService;

@Service("smokeCertService")
public class SmokeCertServiceImpl extends MongoAbstractService<SmokeCert> implements ISmokeCertService {

	@Override
	public SmokeCert findByUserId(String userId) {
		return findOne(new Query(Criteria.where("userId").is(userId)));
	}

	@Override
	public List<SmokeCert> findList(PageEntity page) {
		Query query = new Query();
		List<Order> orders = new ArrayList<Order>();
		orders.add(new Order(Direction.ASC, "status"));
		orders.add(new Order(Direction.DESC, "createTime"));
		query.with(new Sort(orders));
		query.skip(page.getStartRow()).limit(page.getPageSize());
		return findList(query);
	}

}
